package com.asura.student;

import java.util.ArrayList;
import java.util.List;

public class Student {
	private String name;
	private double gpa = 0.0;

	public enum Grade {
		A, B, C, D, E, F
	};

	public Student(String name) {
		this.name = name;
	}

	public Student() {
	}

	public String getName() {
		return name;
	}

	private List<Grade> grades = new ArrayList<Grade>();

/*	public double getGpa() {
		if (grades.isEmpty())
			return 0.0;
		double total = 0.0;
		for (String grade : grades) {
			if (grade.equals("A")) {
				total += 4;
			} else if (grade.equals("B")) {
				total += 3;
			} else if (grade.equals("C")) {
				total += 2;
			} else if (grade.equals("D")) {
				total += 1;
			} else {
				total += 0;
			}
		}
		return total / grades.size();
	}*/
	
	public double getGpa() {
		if (grades.isEmpty())
			return 0.0;
		double total = 0.0;
		for (Grade grade : grades) {
			total += gradePointsFor(grade);
		}
		return total / grades.size();
	}
	
	private int gradePointsFor(Grade grade){
		if (grade == Grade.A) {
			return 4;
		} else if (grade == Grade.B) {
			return 3;
		} else if (grade == Grade.C) {
			return 2;
		} else if (grade == Grade.D) {
			return 1;
		} return 0;
	}

	public void addGrade(Grade grade) {
		grades.add(grade);
	}
}
